package org.xwb.springcloud.messagetype.direct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import org.xwb.springcloud.constant.MqConstant;

import javax.annotation.Resource;

/**
 * @author 10564
 * @description: 直连交换机生产者
 */
@Component
public class DirectProducer {
    private static final Logger log = LoggerFactory.getLogger(DirectProducer.class);

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void senderDirectOneMessage(String message) {
        log.info("\n路由模式生产者one发送消息:{}\n",message);
        //参数1：交换机名称
        //参数2：路由key
        //参数3：消息
        //topic_exchange交换机  需要指定路由key  绑定到该交换机且符合路由key的队列都会收到消息
        rabbitTemplate.convertAndSend(MqConstant.DIRECT_EXCHANGE_NAME,MqConstant.DIRECT_ROUTING_KEY_ONE,message+"ONE");
    }

    public void senderDirectTwoMessage(String message) {
        log.info("\n路由模式生产者two发送消息:{}\n",message);
        //参数1：交换机名称
        //参数2：路由key
        //参数3：消息
        //topic_exchange交换机  需要指定路由key  绑定到该交换机且符合路由key的队列都会收到消息
        rabbitTemplate.convertAndSend(MqConstant.DIRECT_EXCHANGE_NAME,MqConstant.DIRECT_ROUTING_KEY_TWO,message+"TWO");
    }
}
